package cn.dt.system.controller;

import cn.dt.basic.util.AjaxResult;
import cn.dt.basic.util.PageList;
import cn.dt.system.domain.Systemdictionarydetail;
import cn.dt.system.query.SystemdictionarydetailQuery;
import cn.dt.system.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author:代伟
 * date:2022/6/5 9:50
 */
@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;
    /**
     * 查询一条
     * */
    @GetMapping("/{id}")
    public Systemdictionarydetail queryById(@PathVariable("id") Long id){
        return systemdictionarydetailService.queryById(id);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping
    public List<Systemdictionarydetail> queryAll(){
        return systemdictionarydetailService.queryAll();

    }

    /**
     * 高级查询+分页
     * @return
     */
    @PostMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery query){
        return systemdictionarydetailService.queryPage(query);
    }

    /**
     * 删除一条数据
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult
                    .me()
                    .setSuccess(false)
                    .setMessage("网络繁忙，请稍后重试！！");
        }
    }
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        try {
            systemdictionarydetailService.batchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult
                    .me()
                    .setSuccess(false)
                    .setMessage("网络繁忙，请稍后重试！！");
        }
    }

    /**
     * 新增或者修改
     * @param systemdictionarydetail
     * @return
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if(systemdictionarydetail.getId()==null){
                systemdictionarydetailService.save(systemdictionarydetail);
            }else{
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult
                    .me()
                    .setSuccess(false)
                    .setMessage("系统繁忙，请稍后重试");
        }
    }
}
